﻿namespace IPTableAdapters
{
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Configuration;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Diagnostics;

    [HelpKeyword("vs.data.TableAdapter"), DesignerCategory("code"), Designer("Microsoft.VSDesigner.DataSource.Design.TableAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), GeneratedCode("System.Data.Design.TypedDataSetGenerator", "2.0.0.0"), ToolboxItem(true), DataObject(true)]
    public class DocumentTypeTableAdapter : Component
    {
        private SqlDataAdapter _adapter;
        private bool _clearBeforeFill;
        private SqlCommand[] _commandCollection;
        private SqlConnection _connection;

        /*[DebuggerNonUserCode]*/
        public DocumentTypeTableAdapter()
        {
            this.ClearBeforeFill = true;
        }

        [HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode, DataObjectMethod(DataObjectMethodType.Delete, true)]
        public virtual int Delete(string Original_Section, string Original_Type)
        {
            int ret;
            if (Original_Section == null)
            {
                throw new ArgumentNullException("Original_Section");
            }
            this.Adapter.DeleteCommand.Parameters[0].Value = Original_Section;
            if (Original_Type == null)
            {
                throw new ArgumentNullException("Original_Type");
            }
            this.Adapter.DeleteCommand.Parameters[1].Value = Original_Type;
            ConnectionState previousConnectionState = this.Adapter.DeleteCommand.Connection.State;
            if ((this.Adapter.DeleteCommand.Connection.State & ConnectionState.Open) != ConnectionState.Open)
            {
                this.Adapter.DeleteCommand.Connection.Open();
            }
            try
            {
                ret = this.Adapter.DeleteCommand.ExecuteNonQuery();
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    this.Adapter.DeleteCommand.Connection.Close();
                }
            }
            return ret;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false), DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual IP.DocumentTypeDataTable GetDocTypeBySection(string Section)
        {
            this.Adapter.SelectCommand = this.CommandCollection[1];
            if (Section == null)
            {
                this.Adapter.SelectCommand.Parameters[0].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.SelectCommand.Parameters[0].Value = Section;
            }
            IP.DocumentTypeDataTable dataTable = new IP.DocumentTypeDataTable();
            this.Adapter.Fill(dataTable);
            return dataTable;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true), HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode]
        public virtual IP.DocumentTypeDataTable GetDocTypeData()
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            IP.DocumentTypeDataTable dataTable = new IP.DocumentTypeDataTable();
            this.Adapter.Fill(dataTable);
            return dataTable;
        }

        //[DataObjectMethod(DataObjectMethodType.Select, false), DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        //public virtual DataTable GetDocTypeBySection(string Section)
        //{
        //    this.Adapter.SelectCommand = this.CommandCollection[1];
        //    if (Section == null)
        //    {
        //        this.Adapter.SelectCommand.Parameters[0].Value = DBNull.Value;
        //    }
        //    else
        //    {
        //        this.Adapter.SelectCommand.Parameters[0].Value = Section;
        //    }
        //    IP.DocumentTypeDataTable dt;
        //    DataTable dataTable = new DataTable();
        //    this.Adapter.Fill(dataTable);
        //    return dataTable;
        //}

        //[DataObjectMethod(DataObjectMethodType.Select, true), HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode]
        //public virtual DataTable GetDocTypeData()
        //{
        //    this.Adapter.SelectCommand = this.CommandCollection[0];
        //    DataTable dataTable = new DataTable();
        //    this.Adapter.Fill(dataTable);
        //    return dataTable;
        //}

        /*[DebuggerNonUserCode]*/
        private void InitAdapter()
        {
            this._adapter = new SqlDataAdapter();
            DataTableMapping tableMapping = new DataTableMapping();
            tableMapping.SourceTable = "Table";
            tableMapping.DataSetTable = "DocumentType";
            tableMapping.ColumnMappings.Add("Section", "Section");
            tableMapping.ColumnMappings.Add("SectionName", "SectionName");
            tableMapping.ColumnMappings.Add("Type", "Type");
            tableMapping.ColumnMappings.Add("Folder", "Folder");
            tableMapping.ColumnMappings.Add("CreateBy", "CreateBy");
            tableMapping.ColumnMappings.Add("UpdateBy", "UpdateBy");
            tableMapping.ColumnMappings.Add("OwnerGroupID", "OwnerGroupID");
            this._adapter.TableMappings.Add(tableMapping);
            this._adapter.DeleteCommand = new SqlCommand();
            this._adapter.DeleteCommand.Connection = this.Connection;
            this._adapter.DeleteCommand.CommandText = "DELETE FROM DocumentType\r\nWHERE     (Section = @Original_Section) AND (Type = @Original_Type)";
            this._adapter.DeleteCommand.CommandType = CommandType.Text;
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Section", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Section", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Type", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "Type", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.InsertCommand = new SqlCommand();
            this._adapter.InsertCommand.Connection = this.Connection;
            this._adapter.InsertCommand.CommandText = "INSERT INTO DocumentType\r\n                      (Section, TypeSeq, Type, Folder, CreateBy, UpdateBy, OwnerGroupID)\r\nVALUES     (@Section,@TypeSeq,@Type,@Folder,@CreateBy,@UpdateBy,@OwnerGroupID)";
            this._adapter.InsertCommand.CommandType = CommandType.Text;
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Section", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Section", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@TypeSeq", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "TypeSeq", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "Type", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Folder", SqlDbType.NVarChar, 300, ParameterDirection.Input, 0, 0, "Folder", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@CreateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "CreateBy", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@UpdateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "UpdateBy", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@OwnerGroupID", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "OwnerGroupID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand = new SqlCommand();
            this._adapter.UpdateCommand.Connection = this.Connection;
            this._adapter.UpdateCommand.CommandText = "UPDATE    DocumentType\r\nSET              Section = @Section, Type = @Type, TypeSeq = @TypeSeq, Folder = @Folder, UpdateBy = @UpdateBy\r\nWHERE     (Section = @Original_Section) AND (Type = @Original_Type)";
            this._adapter.UpdateCommand.CommandType = CommandType.Text;
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Section", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Section", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "Type", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@TypeSeq", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "TypeSeq", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Folder", SqlDbType.NVarChar, 300, ParameterDirection.Input, 0, 0, "Folder", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@UpdateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "UpdateBy", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Section", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Section", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Type", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "Type", DataRowVersion.Original, false, null, "", "", ""));
        }

        /*[DebuggerNonUserCode]*/
        private void InitCommandCollection()
        {
            this._commandCollection = new SqlCommand[2];
            this._commandCollection[0] = new SqlCommand();
            this._commandCollection[0].Connection = this.Connection;
            /*
             * SELECT dt.Section, ds.Description as SectionName, dt.Type, dt.Folder, dt.CreateBy, dt.UpdateBy, dt.OwnerGroupID 
                FROM DocumentType dt, DocumentSection ds 
             *  where dt.Section=ds.Section*/
            this._commandCollection[0].CommandText = "SELECT dt.Section, ds.Description as SectionName, dt.TypeSeq, dt.Type, dt.Folder, dt.CreateBy, dt.UpdateBy, dt.OwnerGroupID  FROM FROM DocumentType dt, DocumentSection ds where dt.Section=ds.Section";
            this._commandCollection[0].CommandType = CommandType.Text;
            this._commandCollection[1] = new SqlCommand();
            this._commandCollection[1].Connection = this.Connection;
            /*
             
            this._commandCollection[1].CommandText = "SELECT     Section, TypeSeq, Type, Folder, CreateBy, UpdateBy, OwnerGroupID\r\nFROM         DocumentType\r\nWHERE     (Section = @Section) OR\r\n                      (@Section IS NULL)";


             */
            this._commandCollection[1].CommandText = "SELECT DocumentType.Section, ds.Description as SectionName, DocumentType.TypeSeq, DocumentType.Type, DocumentType.Folder, DocumentType.CreateBy, DocumentType.UpdateBy, DocumentType.OwnerGroupID \r\nFROM         DocumentType, DocumentSection ds \r\nWHERE DocumentType.Section=ds.Section and ((DocumentType.Section = @Section) OR ( (@Section IS NULL)))";
            this._commandCollection[1].CommandType = CommandType.Text;
            this._commandCollection[1].Parameters.Add(new SqlParameter("@Section", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Section", DataRowVersion.Current, false, null, "", "", ""));
        }

        /*[DebuggerNonUserCode]*/
        private void InitConnection()
        {
            this._connection = new SqlConnection();
            this._connection.ConnectionString = ConfigurationManager.ConnectionStrings["LocalSqlConnection1"].ConnectionString;
        }

        [DataObjectMethod(DataObjectMethodType.Insert, true), DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Insert(string Section, string TypeSeq, string Type, string Folder, string CreateBy, string UpdateBy, string OwnerGroupID)
        {
            int ret;
            if (Section == null)
            {
                throw new ArgumentNullException("Section");
            }
            this.Adapter.InsertCommand.Parameters[0].Value = Section;
            if (TypeSeq == null)
            {
                throw new ArgumentNullException("TypeSeq");
            }
            this.Adapter.InsertCommand.Parameters[1].Value = TypeSeq;
            if (Type == null)
            {
                throw new ArgumentNullException("Type");
            }
            this.Adapter.InsertCommand.Parameters[2].Value = Type;
            if (Folder == null)
            {
                throw new ArgumentNullException("Folder");
            }
            this.Adapter.InsertCommand.Parameters[3].Value = Folder;
            if (CreateBy == null)
            {
                throw new ArgumentNullException("CreateBy");
            }
            this.Adapter.InsertCommand.Parameters[4].Value = CreateBy;
            if (UpdateBy == null)
            {
                throw new ArgumentNullException("UpdateBy");
            }
            this.Adapter.InsertCommand.Parameters[5].Value = UpdateBy;
            if (OwnerGroupID == null)
            {
                throw new ArgumentNullException("OwnerGroupID");
            }
            this.Adapter.InsertCommand.Parameters[6].Value = OwnerGroupID;
            ConnectionState previousConnectionState = this.Adapter.InsertCommand.Connection.State;
            if ((this.Adapter.InsertCommand.Connection.State & ConnectionState.Open) != ConnectionState.Open)
            {
                this.Adapter.InsertCommand.Connection.Open();
            }
            try
            {
                ret = this.Adapter.InsertCommand.ExecuteNonQuery();
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    this.Adapter.InsertCommand.Connection.Close();
                }
            }
            return ret;
        }

        [DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(IP dataSet)
        {
            return this.Adapter.Update(dataSet, "DocumentType");
        }

        [HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode]
        public virtual int Update(DataRow[] dataRows)
        {
            return this.Adapter.Update(dataRows);
        }

        [DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(IP.DocumentTypeDataTable dataTable)
        {
            return this.Adapter.Update(dataTable);
        }

        [HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode]
        public virtual int Update(DataRow dataRow)
        {
            return this.Adapter.Update(new DataRow[] { dataRow });
        }

        [HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode, DataObjectMethod(DataObjectMethodType.Update, true)]
        public virtual int Update(string Section, string Type, string TypeSeq, string Folder, string UpdateBy, string Original_Section, string Original_Type)
        {
            int ret;
            if (Section == null)
            {
                throw new ArgumentNullException("Section");
            }
            this.Adapter.UpdateCommand.Parameters[0].Value = Section;
            if (Type == null)
            {
                throw new ArgumentNullException("Type");
            }
            this.Adapter.UpdateCommand.Parameters[1].Value = Type;
            if (TypeSeq == null)
            {
                throw new ArgumentNullException("TypeSeq");
            }
            this.Adapter.UpdateCommand.Parameters[2].Value = TypeSeq;
            if (Folder == null)
            {
                throw new ArgumentNullException("Folder");
            }
            this.Adapter.UpdateCommand.Parameters[3].Value = Folder;
            if (UpdateBy == null)
            {
                throw new ArgumentNullException("UpdateBy");
            }
            this.Adapter.UpdateCommand.Parameters[4].Value = UpdateBy;
            if (Original_Section == null)
            {
                throw new ArgumentNullException("Original_Section");
            }
            this.Adapter.UpdateCommand.Parameters[5].Value = Original_Section;
            if (Original_Type == null)
            {
                throw new ArgumentNullException("Original_Type");
            }
            this.Adapter.UpdateCommand.Parameters[6].Value = Original_Type;
            ConnectionState previousConnectionState = this.Adapter.UpdateCommand.Connection.State;
            if ((this.Adapter.UpdateCommand.Connection.State & ConnectionState.Open) != ConnectionState.Open)
            {
                this.Adapter.UpdateCommand.Connection.Open();
            }
            try
            {
                ret = this.Adapter.UpdateCommand.ExecuteNonQuery();
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    this.Adapter.UpdateCommand.Connection.Close();
                }
            }
            return ret;
        }

        /*[DebuggerNonUserCode]*/
        private SqlDataAdapter Adapter
        {
            get
            {
                if (this._adapter == null)
                {
                    this.InitAdapter();
                }
                return this._adapter;
            }
        }

        /*[DebuggerNonUserCode]*/
        public bool ClearBeforeFill
        {
            get
            {
                return this._clearBeforeFill;
            }
            set
            {
                this._clearBeforeFill = value;
            }
        }

        /*[DebuggerNonUserCode]*/
        protected SqlCommand[] CommandCollection
        {
            get
            {
                if (this._commandCollection == null)
                {
                    this.InitCommandCollection();
                }
                return this._commandCollection;
            }
        }

        /*[DebuggerNonUserCode]*/
        internal SqlConnection Connection
        {
            get
            {
                if (this._connection == null)
                {
                    this.InitConnection();
                }
                return this._connection;
            }
            set
            {
                this._connection = value;
                if (this.Adapter.InsertCommand != null)
                {
                    this.Adapter.InsertCommand.Connection = value;
                }
                if (this.Adapter.DeleteCommand != null)
                {
                    this.Adapter.DeleteCommand.Connection = value;
                }
                if (this.Adapter.UpdateCommand != null)
                {
                    this.Adapter.UpdateCommand.Connection = value;
                }
                for (int i = 0; i < this.CommandCollection.Length; i++)
                {
                    if (this.CommandCollection[i] != null)
                    {
                        this.CommandCollection[i].Connection = value;
                    }
                }
            }
        }
    }
}

